/*
 * @Author: your name
 * @Date: 2021-09-20 21:24:18
 * @LastEditTime: 2021-09-21 19:59:16
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \重构项目\briup-ej-app\src\store\ChinaList.js
 */
export default {
  namespaced: true,
  state: {
    chinaEpidemicData:[]
  },
  getters: {
    //返回地图所要数据json
    chinaList(state) {
        // JSON.parse(state.epidemicData.data)
      let chinaObj  = state.chinaEpidemicData.areaTree[0].children
      let newArr = []
      chinaObj.forEach(function(item){
        let name = item.name
        let value = item.total.confirm
        let obj = {}
        obj.name = name
        obj.value = value
        newArr.push(obj)  
      });
      return newArr
    },
    //统计累计
    totalChina(state) {
      let epidemic = new Map()
      let {nowConfirm,noInfect,suspect,nowSevere,confirm,importedCase,heal,dead} = state.chinaEpidemicData.chinaTotal 
      epidemic.set('nowConfirm',nowConfirm)
      epidemic.set('noInfect',noInfect)
      epidemic.set('suspect',suspect)
      epidemic.set('nowSevere',nowSevere)
      epidemic.set('confirm',confirm)
      epidemic.set('importedCase',importedCase)
      epidemic.set('heal',heal)
      epidemic.set('dead',dead)
      return epidemic
    },
    //较昨日
    chinaNowList(state) {
      // JSON.parse(state.epidemicData.data)
    let chinaObj  = state.chinaEpidemicData.areaTree[0].children
    let newArr = []
    chinaObj.forEach(function(item){
      let name = item.name
      let value = item.total.nowConfirm
      let obj = {}
      obj.name = name
      obj.value = value
      newArr.push(obj)  
    });
    return newArr
  },
    //列表数据
    areaDataList(state) {
      let objList = state.chinaEpidemicData.areaTree[0].children
      let newArr = []
      objList.forEach(function(item){
        let {name,total} = item
        let obj = {}
        obj.name = name
        obj.total = total
        newArr.push(obj) 
      })
      return newArr
    }
  },
  mutations:{
     SET_DATA(state,DataList){
       state.chinaEpidemicData = JSON.parse(DataList.data)
     }   
  },
  actions:{
    getChinaData({commit},payload){
      let res = payload
      commit('SET_DATA',res)
    }
  }
}